package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.NewsCommend;
import cn.wolfcode.trip.base.mapper.NewsCommendMapper;
import cn.wolfcode.trip.base.query.NewsCommendQuery;
import cn.wolfcode.trip.base.service.INewsCommendService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
/**
 * 日报推荐业务接口实现类
 */
@Service
public class NewsCommendServiceImpl implements INewsCommendService {

    @Autowired
    private NewsCommendMapper newsCommendMapper;

    /**
     * 分页方法
     * @param qo
     * @return
     */
    public PageInfo query(NewsCommendQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<NewsCommend> list = newsCommendMapper.selectForList(qo);
        return new PageInfo(list);
    }

    /**
     * 新增或修改方法
     * @param
     */
    public void saveOrUpdate(NewsCommend newsCommend) {
        if(newsCommend.getId()!=null){
            newsCommendMapper.updateByPrimaryKey(newsCommend);
        }else{
            newsCommendMapper.insert(newsCommend);
        }
    }

    /**
     * 获取日报推荐的数据
     * @param qo
     * @return
     */
    public PageInfo queryForApp(NewsCommendQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<NewsCommend> list = newsCommendMapper.selectForAppList(qo);
        return new PageInfo(list);
    }

}
